<?php
session_start();

if (!isset($_SESSION['AccUnique']) || $_SESSION['AccUnique'] == "") {
    echo "<script type='text/javascript'>location.href='index.php'</script>";
}

require_once 'common/config.php';
require_once 'common/conn.php';
require_once 'common/function.php';

require_once 'db/account.db.php';
require_once 'db/accountMoney.db.php';

$username = isset($_GET['username']) ? trim($_GET['username']) : "";

$id = $_SESSION['AccUnique'];

$dbc = new DBC();

$balance = 0;

$accountDb = new AccountDb($dbc);

$data = $accountDb->getAccountById($id);

if (isArrayNotEmpty($data)) {
    $accountId = $data[0]['AccountID'];
}
$accountMoneyDb = new AccountMoneyDb($dbc);

$accountMoneyData = $accountMoneyDb->getAccountMoney($id);
if (isArrayNotEmpty($accountMoneyData)) {
    $balance = $accountMoneyData[0]['Balance'];
}

$otherAccUnique = "";
if ($username != "") {
    $other = $accountDb->getAccountByName($username);
    if (isArrayNotEmpty($other)) {
        $otherAccUnique = $other[0]['AccUnique'];
    }
}
?>
<!DOCTYPE html>
<html>
    <head>
        <title>赠送金币</title>
        <meta charset="UTF-8">

        <meta name="description" content="Flat UI Kit Free is a Twitter Bootstrap Framework design and Theme, this responsive framework includes a PSD and HTML version."/>

        <meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">

        <!-- Loading Bootstrap -->
        <link href="<?php echo $flatUi; ?>dist/css/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

        <!-- Loading Flat UI -->
        <link href="<?php echo $flatUi; ?>dist/css/flat-ui.css" rel="stylesheet">
        <link href="<?php echo $flatUi; ?>docs/assets/css/demo.css" rel="stylesheet">

        <link rel="shortcut icon" href="<?php echo $flatUi; ?>img/favicon.ico">

        <script src="<?php echo $flatUi; ?>js/jquery-1.11.3.js"></script>
        <style>
            html body{
                width:800px;
                height:586px;
            }
        </style>
        
    </head>
    <body>
        <div class="container">
            <!--            <h1 class="demo-section-title text-center">荣耀ol - 在线商城</h1>-->
            <h3 class="demo-panel-title"><a href="index.php">回首页</a></h3>
            <div class="row">
                <div class="col-xs-1"></div>
                <div class="col-xs-11">
                    
                        <?php
                        if (isset($_SESSION['AccountID']) && $_SESSION['AccountID'] != "") {
                            $accountMoneyDb = new AccountMoneyDb($dbc);
                            $accountMoney = $accountMoneyDb->getAccountMoney($_SESSION['AccUnique']);
                            $balance = 0;
                            if ($accountMoney && isArrayNotEmpty($accountMoney)) {
                                $balance = $accountMoney[0]['Balance'];
                            }
                            ?>
                        用户：<?php echo $_SESSION['AccountID']; ?>&nbsp;&nbsp;余额：<?php echo $balance; ?>&nbsp;&nbsp;<a href="cart.php">查看购物车</a>
                        <?php } else { ?>
                            <form action="action/account.action.php" method="post">
                                <div class="demo-browser-side">
                                    <div></div>
                                    <div class="demo-browser-action">
                                        <input type="hidden" name="action" value="login"/>
                                        <input type="text" class="form-control" name="username" placeholder="用户名"/>
                                        <br>
                                        <input type="password" class="form-control" name="password" placeholder="密码"/>
                                        <br>
                                        <input type="submit" class="form-control" value="登录"/>
                                    </div>
                                </div>
                            </form>
                        <?php } ?>
                </div>
                <div class="col-xs-12">
                    <div style="text-align: center; width: 780px;">
                        <h1>
                            赠送金币
                        </h1>
                    </div>
                    <?php if ($username == "") { ?>
                    <form class="form-horizontal" role="form" action="action/account.action.php" method="POST" enctype="multipart/form-data" style="width:780px;">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">赠送用户</label>
                                <div class="col-sm-10">
                                    <input name="action" type="hidden" value="searchUser">                        
                                    <input class="form-control" id="username" name="username" type="text" value="" placeholder="请输入要赠送用户的账号">
                                </div>
                            </div>
                            <div style="width:100%; text-align: center">
                                <input type="submit" class="btn btn-primary" value="查找用户"/>
                            </div>
                        </form>
                    <?php } ?>
                    <br/><br/>
                    <form class="form-horizontal" role="form" action="action/account.action.php" method="POST" enctype="multipart/form-data" style="width:780px;">
                        <?php if ($username != "") { ?>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">用户</label>
                                <div class="col-sm-10">                                    
                                    <input id="otherAccUnique" name="otherAccUnique" type="hidden" value="<?php echo $otherAccUnique; ?>">
                                    <input class="form-control" id="username" name="username" type="text" value="<?php echo $username; ?>" disabled="disabled">
                                </div>
                            </div>
                        
                        <div class="form-group">
                            <label class="col-sm-2 control-label">我的余额</label>
                            <div class="col-sm-10">
                                <input name="action" type="hidden" value="giftGold">
                                <input id="accUnique" name="accUnique" type="hidden" value="<?php echo $id; ?>">
                                <input class="form-control" id="itemName" name="itemName" type="text" value="<?php echo $balance; ?>" disabled="disabled">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">赠送金币</label>
                            <div class="col-sm-10">
                                <input class="form-control" id="gold" name="gold" type="text" value="0" required>
                            </div>
                        </div>
                        <div style="width:100%; text-align: center">
                            <input type="submit" class="btn btn-primary" value="赠送"/>
                        </div>
                        <?php } ?>
                    </form>
                </div>
            </div> <!-- /download area -->
        </div> <!-- /container -->
    </body>
</html>